(* ::Package:: *)

<<Histograms`


SetDirectory["C:\\Projects\\branches\\HMC_core\\output"]


param=OpenRead["..\\input\\params_hmc.txt"];
Skip[param,{Number}];
Tstart=Read[param,Number];
Tstep=Read[param,Number];
Tend=Read[param,Number];
Pacc=Read[param,Number];
Nmd=Read[param,Number];
Nmc=Read[param,Number];
Skip[param,{Number}];
Nruns=Read[param,Number];
NumDim=Read[param,Number];

Close[param];

templist=Range[Tstart,Tend,Tstep];

funcname="Griewank\\Mod";

sucFinal=Array[b,{Length[templist],2}];


loadstring=".\\"<>funcname<>"\\HMC_Solution.out";

fid=OpenRead[loadstring];

Skip[fid,String];
Skip[fid,String];
Skip[fid,String];
Skip[fid,String];
Skip[fid,String];


index=1;
For[temp=Tstart,temp<=Tend,temp+=Tstep,
 nSuccess=0;
 Print["Temp = ", temp];
 For[iNruns=1,iNruns<=Nruns,iNruns++,
  (*Skip[fid,Number];*)
  x=Read[fid,Number];
  Skip[fid,Number];
  Skip[fid,Number];
  Skip[fid,Number];
  Skip[fid,Number];

  If[x<(1*(10^-3)),nSuccess++,Null];

  Clear[x];
 ];
 Skip[fid,String];
 Skip[fid,String];
 Skip[fid,String];

 sucFinal[[index,2]]=nSuccess;
 sucFinal[[index,1]]=templist[[index]];
 index+=1;
]


newSucFinal=Array[sf,Length[templist]];

For[j=1,j<=Length[templist],j++,
 newSucFinal[[j]]=sucFinal[[j,2]];
]


ListPlot[Tooltip[sucFinal],PlotRange->{{Tstart,Tend},{-0.25,Nruns+0.25}},Joined->False,AxesLabel->{Temperature,No. Success},AxesOrigin->{Tstart,0},PlotStyle->PointSize[Medium]]


Histogram[newSucFinal,FrequencyData->True,HistogramRange->{Tstart,Tend},HistogramCategories->Automatic]


Remove["Histogram"]
